<?php

namespace app\admin\controller;

use think\Controller;
use think\Request;
use think\Session;
use think\Db;

class Setting extends Base
{

    /**
     * @param Request $request
     * @return \think\response\View
     */
    public function setting(Request $request)
    {
        $max_money = $request->param('max_money') ?: '';
        $min_money = $request->param('min_money') ?: '';
        $poundage  = $request->param('poundage') ?: '';
        $extract_days_max_withdraw  = $request->param('extract_days_max_withdraw');

        if ($max_money && $min_money && $poundage) {
            Db::table('ad_extract')->where('id', 1)->update([
                'extract_money' => $max_money,
                'extract_poundage' => $poundage,
                'extract_days_max_withdraw' => $extract_days_max_withdraw,
                'extract_min' => $min_money
            ]);
        }
        $data = Db::table('ad_extract')->find(1);
        return view('setting', compact('data'));
    }


    /**
     * @param Request $request
     * @return \think\response\View
     * 分润设置
     */
    public function divideds(Request $request)
    {
        $divided     = $request->param('divided') ?: '';
        $two_divided = $request->param('two_divided') ?: '';
        $invitation  = $request->param('invitation') ?: '';
        if ($divided && $two_divided && $invitation) {
            Db::table('ad_divided')->where('id', 1)->update([
                'cz_divided' => $divided,
                'cz_two_divided' => $two_divided,
                'cz_invitation' => $invitation
            ]);
        }
        $data = Db::table('ad_divided')->find(1);
        return view('divideds', compact('data'));
    }
}